package org.goj.common.model;

import org.springframework.util.Assert;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author CK
 * @date 2021/3/17 9:19
 */
public class RequestUtil {

    public static HttpServletRequest request(){
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        Assert.notNull(servletRequestAttributes,"获取request对象失败！");
        return servletRequestAttributes.getRequest();
    }

    public static HttpServletResponse response(){
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        Assert.notNull(servletRequestAttributes,"获取response对象失败！");
        return servletRequestAttributes.getResponse();
    }

}
